var mysql = require('mysql');

var connection = mysql.createConnection({
  host     : '64.23.72.78',
  user     : 'talkative',
  password : 'welcome1',
  insecureAuth: true
});

connection.connect();
connection.query('USE talkative');

exports.login = function(username, password, handler) {
	connection.query('SELECT * FROM ttmembers WHERE user = ? and pass = ?', [username, password], function(err, rows, fields) {
		var result = false;
		if (rows.length > 0) {
			result = true;
		}
		
		handler(result);
	});
};

exports.getBuddies = function(username, handler) {
	connection.query('SELECT friend FROM ttfriends WHERE user = ?', [username], function(err, rows, fields) {
		handler(rows);
	});
};
